import 'package:flutter/material.dart';
import 'package:realmega_ota/realmega/history_info.dart';
import 'package:realmega_ota/realmega/history_manager.dart';

import 'constants.dart';

class HistoryWidget extends StatelessWidget{

  final double MARGIN_LENGTH = COMMON_MARGIN_LENGTH;


  @override
  Widget build(BuildContext context) {
    HistoryManager.instance.loadHistoryList();
    return SingleChildScrollView(
      child: StreamBuilder<List<HistoryInfo>>(
        stream: HistoryManager.instance.runningHistory,
        initialData: [],
        builder: (c, snapshot) => Column(
          children: snapshot.data!.map((d) => Column(
            children: [
              Row(
                children: [
                  Container(width: MARGIN_LENGTH,),
                  Text(d.name, style: const TextStyle(
                      fontSize: 20,
                      color: Color(0xff333333)
                  ),),
                  Spacer(),
                  Text(d.status, style: const TextStyle(
                      fontSize: 18,
                      color: Color(0xffff0000)
                  ),),
                  Container(width: MARGIN_LENGTH,)
                ],
              ),
              Row(
                children: [
                  Container(width: MARGIN_LENGTH,),
                  Text(d.addr, style: const TextStyle(
                      fontSize: 14,
                      color: Color(0xff666666)
                  ),),
                  Spacer(),
                ],
              ),
              Row(
                children: [
                  Container(width: MARGIN_LENGTH,),
                  Text(d.dateTime, style: const TextStyle(
                      fontSize: 14,
                      color: Color(0xff666666)
                  ),),
                  Spacer(),
                  Text(d.msg, style: const TextStyle(
                      fontSize: 14,
                      color: Color(0xff666666)
                  ),),
                  Container(width: MARGIN_LENGTH,)
                ],
              ),
              Divider(thickness: 1,indent: MARGIN_LENGTH,)
            ],
          )).toList(),
        ),
      ),
    );
  }
}

// class _HistoryState extends State<HistoryWidget>{
//   @override
//   Widget build(BuildContext context) {
//
//   }
//
// }